<template>
<div class='rc-container'>
  <el-table
    :data="projectList"
    style="width: 100%"
    stripe
    empty-text="暂无数据">
    <el-table-column
      prop="projectName"
      label="标题"
      align="center"
      width="180"
    />
    <el-table-column
      align="center"
      prop="createTime"
      :formatter="dateFormat"
      label="创建时间"
    />
    <el-table-column
      align="center"
      prop="updateTime"
      :formatter="dateFormat"
      label="删除时间"
    />
    <el-table-column
      align="center"
      label="操作">
      <template slot-scope="scope">
        <el-popconfirm
          confirm-button-text='好的'
          cancel-button-text='不用了'
          icon="el-icon-info"
          icon-color="red"
          title="确定恢复该项目吗？"
          @confirm='restoreProject(scope.row.projectKey,1)'
        >
          <el-button slot="reference">恢复</el-button>
        </el-popconfirm>
        <el-popconfirm
          confirm-button-text='好的'
          cancel-button-text='不用了'
          icon="el-icon-info"
          icon-color="red"
          title="确定删除该项目吗？"
          @confirm='deleteProject(scope.row.projectKey,1)'
        >
          <el-button slot="reference">删除</el-button>
        </el-popconfirm>
      </template>
    </el-table-column>
  </el-table>
</div>
</template>

<script>
import moment from 'moment'

export default {
  name: 'Recycle',
  data() {
    return {
    total: 0,
      queryParams: {
        current: 1,
        size: 10,
        projectName: '',
        beginDateTime: null,
        endDateTime: null,
        status: null,
        delete: true
      },
      projectList: [],
      projectListLoading: true
    }
  },
  methods: {
    dateFormat (row,column) {
      const date = row[column.property];
      if (date == undefined) {return ''};
      return moment(date).format('YYYY-MM-DD HH:mm:ss')
    },
    queryRecycleProjectPage () {
      this.$http.post('project/page',
        this.queryParams
      ).then(res => {
        const { list, total, size } = res.data.data
        this.projectList = list
        this.total = total
        this.queryParams.size = size
        this.projectListLoading = false
      })
    },
    restoreProject(key) {
      this.$http.post('project/restore',
        { projectKey: key })
        .then(res => {
        if (res.data) {
          this.$message('恢复成功')
          this.queryRecycleProjectPage()
        }
      }).catch(err => {
        console.log(err)
      })
    },
    deleteProject(key) {

    }
  },
  mounted () {
    this.queryRecycleProjectPage()
  }
}
</script>

<style scoped>
.rc-container {
  display: flex;
  width: 100%;
  height: 100%;
  flex-direction: column;
  align-items: center;
  align-content: center;
}
.back-view {
  display: flex;
  width: 80%;
  align-content: flex-start;
  margin: 10px;
}
</style>
